<%-- 
    Document   : editProduct
    Created on : Jan 10, 2013, 12:44:11 PM
    Author     : berto
--%>

<%@page import="it.unitn.science.matr155863_148346_145963.bccastestore.items.Product"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit product</title>
    </head>
    <body>
        <%
         Product p=(Product)request.getAttribute("product");
        %>
        <div class="content">
            <h1>Edit product:</h1>
            <%
                String mess="";
                if(request.getAttribute("error_on")!=null){
                    mess="Unable to add the product.<br/>"
                    + "You have an error on field:<br/>"
                    + (String)request.getAttribute("error_on") ;
                }
            %>
            <p id="edit_product_error_log"><%=mess%></p>
            <h2><%=p.getName()%></h2>
            <img src="<%=request.getContextPath()%>/immagini/prodotti/<%=p.getImageName()%>"/>
            <div class="details">
                <form name="form_edit_product" method="post" 
                      action="<%=response.encodeURL(request.getContextPath()+"/contents/user/editProduct")%>">
                    <input type="hidden" name="id" value="<%=p.getId()%>"/>
                    <input type="hidden" name="update" value="<%=p.getId()%>"/>
                <h4>Quantity:</h4><input type="text "name="quantity" value="<%=p.getQuantity()%>" /><p> <%=p.getUmName()%> ;</p>
                <h4>Description:</h4><input type="text" name="description" value="<%=p.getHumanDescription()%>" />
                <input type="reset" name="reset"  value="Reset" /> 
                <input type="button" onclick="ValidateProduct()" name="edit_product" value="Update"
                                    />
                                                <script language="javascript">
  function ValidateProduct(){
     var quantity = document.form_edit_product.quantity.value;
     var description = document.form_edit_product.description.value;
     var errorLog=document.getElementById("edit_product_error_log");
     
	if ((quantity== "")||(isNaN(quantity)) ||(parseInt(quantity)<=0) ){
           errorLog.innerHTML='Quantity must be more than 0.';
           document.form_edit_product.quantity.focus();
           return false;
        }
        else if ((description== "") || (description== "undefined")) {
           errorLog.innerHTML='Insert a description';
           document.form_edit_product.description.focus();
           return false;
        }
        //INVIA IL form_register
        else {
           document.form_edit_product.submit();
        }
  }
</script>
            </form>
            </div>
        </div>
    </body>
</html>
